/* GSUniteGwDAO.java
 *
 * Project/Product: GWBS2009
 *
 * Modify Information:
 * =============================================================================
 *   Author	Date       Description
 *   ----------	---------- ---------------------------------------------------
 *   peng.ning	2009-3-12	First release
 *
 * Licensed Materials - Property of APEP
 * =============================================================================
 *    (C) COPYRIGHT Shanghai Auto Mart E-Procurement Co., Ltd. 2007 - 2009
 *    All Rights Reserved.
 *
 *    This software is the confidential and proprietary information of
 *    Shanghai Auto Mart E-Procurement Co., Ltd. ("Confidential Information").
 *    You shall not disclose such Confidential Information and shall use it only
 *    in accordance with the terms of the license agreement you entered into 
 *    with Shanghai Auto Mart E-Procurement Co., Ltd.
 *
 * Noties:
 * =============================================================================
 * 
 */

package com.hitrust.gs.dao;

import java.sql.SQLException;
import java.util.ArrayList;

import system.base.User;

import com.hitrust.gs.bean.GSUserMenuInfoBean;
import com.hitrust.gs.bean.GSWareHouseBean;
import com.hitrust.gs.lib.GSLogWriter;
import com.hitrust.gs.lib.db.GSBaseDAO;
import com.hitrust.gs.util.exception.GSException;
/**
 * gs功能移植入gw新增dao
 * */
public class GSUniteGwDAO extends GSBaseDAO{
    /***
     * 获取自己及所属仓库
     * **/
    public ArrayList queryWareHouse(String wareHouseCode) throws GSException{
        String sql = "select * from t_warehouse where code like '"+wareHouseCode+"%' and is_show='1'  order by code,length(code)";
        Object[] tobj={};
        ArrayList wareHouseList=new ArrayList();
        try {
            wareHouseList=this.executeQuery(new GSWareHouseBean(), sql, tobj);
        } catch (Exception e) {
            GSLogWriter.error(this,e.toString());
            throw new GSException(GSException.E19999,GSException.E19999_MSG);
        }
        return wareHouseList;
    }
    
    
    /***
     * 获取自己及所属仓库（订货单位所属分公司已经在仓库执行配置表中已经设置为1）
     * parameter wareHouseCode 
     * **/
    public ArrayList queryWareHouseAndStorageConfig(String wareHouseCode) throws GSException{
        String sql = "  SELECT *  FROM t_warehouse tw, t_warehouse_storage_config twsc where " +
        		"  tw.code = twsc.WAREHOUSE_CODE AND twsc.status = 1 "+
        		"and code like '"+wareHouseCode+"%' and is_show='1'  order by code,length(code)";
        Object[] tobj={};
        ArrayList wareHouseList=new ArrayList();
        try {
            wareHouseList=this.executeQuery(new GSWareHouseBean(), sql, tobj);
        } catch (Exception e) {
            GSLogWriter.error(this,e.toString());
            throw new GSException(GSException.E19999,GSException.E19999_MSG);
        }
        return wareHouseList;
    }
    
    /***
     * 获取自己及所属仓库(只显示分公司)
     * parameter wareHouseCode 
     * **/
    public ArrayList queryCompany(String wareHouseCode) throws GSException{
        String sql = "select * from t_warehouse where code like '"+wareHouseCode+"%' and length(code) = 6 and is_show='1'  order by code,length(code)";
        Object[] tobj={};
        ArrayList wareHouseList=new ArrayList();
        try {
            wareHouseList=this.executeQuery(new GSWareHouseBean(), sql, tobj);
        } catch (Exception e) {
            GSLogWriter.error(this,e.toString());
            throw new GSException(GSException.E19999,GSException.E19999_MSG);
        }
        return wareHouseList;
    }
    
    
    /**
     * 根据code获取仓库信息
     * **/
    public GSWareHouseBean queryWareHouseByCode(String code) throws GSException{
        String sql = "select * from t_warehouse where code = '"+code+"'";
        Object[] tobj={};
        GSWareHouseBean tmp=new GSWareHouseBean();
        try {
            ArrayList wareHouseList=this.executeQuery(new GSWareHouseBean(), sql, tobj);
            if (wareHouseList.size()>0) {
              tmp=(GSWareHouseBean) wareHouseList.get(0);  
            }
        } catch (Exception e) {
            GSLogWriter.error(this,e.toString());
            throw new GSException(GSException.E19999,GSException.E19999_MSG);
        }
        return tmp;
    }
    /**
     * 获取登录用户权限
     * **/
    public ArrayList queryUserMenuInfo(String userid) throws GSException{
        String sql="select * from t_user_menuinfo where user_id=?";
        Object[] tobj={userid};
        ArrayList menuInfolist=new ArrayList();
        try {
            menuInfolist=this.executeQuery(new GSUserMenuInfoBean(), sql, tobj);
        }catch (Exception e) {
            GSLogWriter.error(this,e.toString());
            throw new GSException(GSException.E19999,GSException.E19999_MSG);
        }
        return menuInfolist;
    }
    
    /** 根据编码获得仓库名称  */
    public String getWarehouseName(String code){
        String sql = "select * from t_warehouse where code = ?";
        Object[] tobj={code};
        ArrayList list = new ArrayList();
        try {
            list = this.executeQuery(new GSWareHouseBean(), sql, tobj);
            if(list != null && list.size() > 0){
                GSWareHouseBean bean = (GSWareHouseBean)list.get(0);
                return bean.getName();
            }
        } catch (SQLException e) {
            
            e.printStackTrace();
        } catch (Exception e) {
            
            e.printStackTrace();
        }
        return "";
    }
}
